#define _CRT_SECURE_NO_WARNINGS
//作者：宋安康
// MyDialog.cpp  

#include "MyDialog.h"  
#include "MyEdit.h"  
#include "stdafx.h"  
#include "MyApp.h"  
#include "MyDialog.h"  
#include "afxdialogex.h"  

CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
    : CDialogEx(IDD_MYDIALOG_DIALOG, pParent)
{
}

CMyDialog::~CMyDialog()
{
}

void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMyDialog, CDialogEx)
    ON_BN_CLICKED(IDOK, &CMyDialog::OnBnClickedOk)
END_MESSAGE_MAP()

void CMyDialog::OnBnClickedOk()
{
    MessageBox(_T("Hello World!"));
}
BOOL CMyDialog::OnInitDialog()
{
    CDialog::OnInitDialog();

    // 替换编辑框控件为自定义的CMyEdit控件  
    CEdit* pOldEdit = GetDlgItem(IDC_EDIT1);
    CMyEdit* pNewEdit = new CMyEdit(pOldEdit->GetSafeHwnd());
    pNewEdit->SetWindowPos(NULL, pOldEdit->GetWindowRect(), SWP_SHOWWINDOW);
    pOldEdit->DestroyWindow();
    ReplaceCtrl(*pNewEdit, IDC_EDIT1);

    return TRUE;  // 返回 TRUE 除非你对控件设置焦点  
}

// MyDialog.cpp  

void CMyDialog::OnBnClickedOk()
{
    // 设置编辑框的背景颜色为红色  
    CMyEdit* pMyEdit = (CMyEdit*)GetDlgItem(IDC_EDIT1);
    pMyEdit->SetBackgroundColor(RGB(255, 0, 0));
}